home *** CD-ROM | disk | FTP | other *** search
/ Trading on the Edge / Trading On The Edge - CD-ROM Toolkit (Wayzata Technology)(2031)(1994).bin / pc / pc_files / mktdata / econdata / docutils / test.cpp < prev   
C/C++ Source or Header  |  1992-02-09  |  2KB  |  102 lines

  1. #include <iostream.h>    // for cout
  2. #include <ctype.h>        // for isdigit()
  3. #include <stdio.h>        // for fgets()
  4. #include <alloc.h>        // for coreleft()
  5. #include <stdlib.h>        // for atof()
  6. #include <conio.h>        // for cprintf()
  7. #include "bump.h"
  8.  
  9. void sub();
  10. void tap();
  11.  
  12. main()
  13. {
  14.     unsigned long core;
  15.     core = coreleft();
  16.     sub();
  17.     printf("Core at begining: %lu \n", core);
  18.     printf("Core at end     : %lu \n", coreleft());
  19.     }
  20.  
  21. void sub()
  22. {
  23.     int i, j;
  24.     Vector a(4),at(1,4),b(4),c(4),ct(1,4);
  25.     Matrix A(4,4),B(4,4),C(4,4),D(4,1),E(1,1);
  26.     A.ReadA("amatrix");
  27.     A.Display("Here is the A matrix:");
  28.  
  29.     B = 2.*A;
  30.     B.Display("This is 2.*A.");
  31.     B = A/2.;
  32.     B.Display("and this is A/2.");
  33.     for (i = 1; i <= 4; i++){
  34.         for(j = 1; j <= 4; j++)
  35.             B[i][j] = A[i][j]*A[i][j];
  36.         }
  37.     B.Display("This is the element-by-element square of A.");
  38.     tap();
  39.     // Inversion is indicated by ! in front of the matrix.
  40.     B = !A; //Invert it
  41.     B.Display("and here is B = !A ( A inverse):");
  42.     C = A*B;
  43.     // This next Display will have column width of 15 and 6 decimal places
  44.     C.Display("This is A*!A (should be I):",15,6);
  45.     tap();
  46.     B = (A + A)*!A;
  47.     B.Display("B = (A+A)*!A. Should be 2I");
  48.     tap();
  49.     C = A*A;
  50.     C.Display("A*A:");
  51.     C = (A+A)*(A+A);
  52.     C.Display("(A+A)*(A+A). Should be 4 times the matrix above.");
  53.     tap();
  54.     B = ~A;
  55.     A.Display("Here is A again.");
  56.     B.Display("and this is ~A, A transpose.");
  57.     tap();
  58.  
  59.     // Now some tests with vectors
  60.     a.ReadA("avector");
  61.     at = ~a;
  62.     a.Display("This is the a vector:");
  63.     at.Display("and this is a'. The difference doesn't show in the display.");
  64.  
  65.     b = 2.*a;
  66.     b.Display("This is b = 2.*a");
  67.     b = a/2.;
  68.     b.Display("and this is a/2.");
  69.  
  70.  
  71.     D << a;
  72.     D.Display("And this is D << a :");
  73.     tap();
  74.  
  75.     c = A*a;
  76.     c.Display("This is  A*a");
  77.     ct = ~a*~A;
  78.     ct.Display("This is ~a*~A. Should look the same as the above.");
  79.     tap();
  80.     B = ~A*A;
  81.     B.Display("This is ~A*A");
  82.     // Tests of the / operator
  83.     B = A/A;
  84.     B.Display("This is A/A. Should be the same as the above.");
  85.     tap();
  86.     c = A/a;
  87.     ct = a/A;
  88.     c.Display("This is A/a:");
  89.     ct.Display("This is a/A. Should look like the above.");
  90.     tap();
  91.     E = a/a;
  92.     B = at/at;
  93.     E.Display("This is a/a:");
  94.     B.Display("This is at/at:");
  95.     printf("\nEnd of test.\n");
  96.     }
  97. void tap()
  98. {
  99.     cerr << "\nTap a key to continue.  ESC to exit.";
  100.     if(getch() == 27) exit(1);
  101.     }
  102.